package group5_Project3;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class StudentForm extends PersonForm implements ActionListener {
    public String studentid;
    private float gpa;
    public String advisor;
    static JFrame frame;

    static JPanel sPanel;
    static JPanel buttons;
    public static StudentForm s1;
    public static void main(String[] args){
      frame = new JFrame("Student");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container pane = frame.getContentPane();
      pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
      JPanel sPanel = new JPanel(new GridLayout(0,2));
      sPanel = new JPanel(new GridLayout(0,2));
      sPanel.add(new JLabel("First Name:"));
      final JTextField fName = new JTextField();
      sPanel.add(fName);
      sPanel.add(new JLabel("Last Name:"));
      final JTextField lName = new JTextField(); 
      sPanel.add(lName);
      sPanel.add(new JLabel("SSN:"));
      final JTextField ssn = new JTextField();
      sPanel.add(ssn);
      sPanel.add(new JLabel("Age:"));
      final JTextField age = new JTextField();
      sPanel.add(age);
      sPanel.add(new JLabel("Student ID:"));
      final JTextField studentid1 = new JTextField();
      sPanel.add(studentid1);
      sPanel.add(new JLabel("GPA:"));
      final JTextField gpa1 = new JTextField(); 
      sPanel.add(gpa1);
      sPanel.add(new JLabel("Advisor:"));
      final JTextField advisor1 = new JTextField();
      sPanel.add(advisor1);
      frame.add(sPanel);
         
      JButton submit = new JButton("Submit");
      submit.addActionListener(new ActionListener() {
                  
    	   @Override
           public void actionPerformed(ActionEvent e) {
        		int age1 = Integer.parseInt(age.getText());
        		Float gpa2 = (float) Integer.parseInt(gpa1.getText());     
           
                          
                s1 = new StudentForm(fName.getText(), lName.getText(), ssn.getText(), age1, 
                		studentid1.getText(), gpa2, advisor1.getText()); 
                  }
          });
         
      sPanel.add(submit);
                  
      JButton cancel = new JButton("Cancel");
      cancel.addActionListener(new StudentForm());
      sPanel.add(cancel);
      frame.pack();
      frame.setVisible(true);
       }
      
      public StudentForm(){
          }
      public StudentForm(String firstname, String lastname, String ssn, int age,
    		  String studentid, Float gpa, String advisor){
        super(firstname, lastname, ssn, age);
        this.studentid = studentid;
        this.setGPA(gpa);
        this.advisor = advisor;
        System.out.println(this);
          }

        public float getGPA() 
          {
        	return gpa;
          }
          
       public void setGPA(float gpa) 
          {
         this.gpa = gpa;
          } 

          @Override
       public String toString()
          {
         return "First Name: " + this.firstname + "\nLastName: " + this.lastname + 
        		 "\nSSN: " + this.getSsn() + "\nAge: " + this.age + 
 				 "\nStudent ID: " + this.studentid + "\nGPA: " + this.getGPA() +  
                 "\nAdvisor: " + this.advisor;
                          }
      @Override
      public void actionPerformed(ActionEvent e) {
        System.exit(0);
          }
}